﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office"><head>
<?php include('vh.php'); ?>
	<!-- Add elastic library -->
	<script src="<?=base_url().$ldr?>scripts/lib/jquery.elastic.source.js"></script>
	<script src="<?=base_url().$ldr?>scripts/lib/jquery.tinyscrollbar.min.js"></script>
<script type="text/javascript">
	$(document).ready(function() {
		jQuery(".addComment").live('click', function() {
			id = jQuery(this).attr("rel");
			jQuery("#commentBox-"+id).toggle();
		});
		
		
		jQuery(".viewCommentsLink").live('click', function() {
			id = jQuery(this).attr("idbd");
			jQuery("#viewComments-"+id).toggle();
		});
		
	
		// the below function handles the procedures needed to add a comment
		jQuery(".textbox1").live('keydown', function(event) {
	    	var keyCode = event.keyCode || event.which;
			if (keyCode === 13) {
				// below is the bootstrapper for the addComment function
				if ($.trim($($(this)).val()) == '') { // if updater contains only spaces, alert user
					alert("Please add something meaningful");
				} else if ($($(this)).val().length === 0) { // if commentBox contains nothing, alert user
					alert("Please type something meaningful");
				} else if ($($(this)).val().length > 0) { // if commentBox contains useful content, process addComment()
					addComment($(this));
	        	}
	        }
		});
		
		
		function addComment(e) {
			var id = $(e).attr("id"); // grab post id
			var postuserid = $(e).attr("postuserid"); // grab posting user id
			var newId = id.replace("commentBox-", ""); // strip 'commentBox' from grabbed post id
			$.getJSON('<?=base_url()?>index.php/regUserDash/checkIsLoggedIn', function(data) {
            	if (data.loggedIn == true) {
            		$.ajax({
						type: "POST",
						dataType: "JSON",
						url: "<?=base_url()?>index.php/regUserDash/checkIsLoggedIn",
						data: {
							newid: newid,
							userid: postuserid
						},
						success: function() {
							if (data.isMembershipSame === true) {
								alert("truee");
							} else if (data.isMembershipSame === false) {
								alert("falsee");
							}
						}
					});
            	} else if (data.loggedIn == false) {
            		if (window.confirm('You are not logged in. Please login to continue')) {
            			$("#dd").effect("shake", {times:3}, 100);
            		} else {
            			return;
            		}
            	}
        	});
		}
	});
</script>
<body>
			<table align="left" style="width: 26%" class="status-updater-box1">
				<tr>
					<td>
						<textarea autofocus id="updater" placeholder="What's on your mind?" class="updaterTextarea" name="TextArea2" style="border-radius: 3px; width: 499px; height: -3px" cols="20" rows="1"></textarea></td>
					</tr>
				<tr>
					<td class="right">
						<table cellpadding="0" cellspacing="0" style="width: 100%">
							<tr>
								<td class="left" style="width: 477px">
									&nbsp;<a class="grab"><strong>Grab Images</strong></a>&nbsp;&nbsp;
									<a class="grab"><strong>Grab Links</strong></a>
								</td>
								<td>
									<input name="share" id="shareButton" type="submit" value="Share" style="width: 58px; height: 28px" class="button1" />
								</td>
							</tr>
						</table>
					</td>
				</tr>
		</table>
		<td valign="top" style="width: 506px">

<?php   $this->load->helper('date');
        $query = $this->db->query("SELECT * FROM wallPosts, users WHERE users.userid = wallPosts.postingUserId ORDER BY users.userid DESC LIMIT 100");
        foreach ($query->result() as $row) {
        	?>

<table cellpadding="0" cellspacing="0" style="width: 506px; height: 49px">
	<tr>
		<td valign="top" rowspan="5">
        <img style="padding: 3px" id="defaultImg a1" src="<?php echo base_url().$row->defaultImgURI; ?>" width="59" height="64" /></td>
		<td valign="top">
        <a href="<?=base_url()?>index.php/routers/regUserDash?id=<?=$row->userid?>&requestedPageType=userProfiles" class="font1 link-font1 postname"><b><?php echo $row->firstname . " " . $row->lastname; ?></b></a>
		<td style="height: 19px"></td>
	</tr>
	<tr>
		<td valign="top">
			<span class="font1"><?=$row->entryData?></span>
		</td>
		<td></td>
	</tr>
	<tr>
		<td valign="top">
		<a class="link-font1 addComment" rel="<?=$row->idwallPosts?>">Add Comment&nbsp; </a><span class="font1">|&nbsp;</span> <a class="link-font1 viewCommentsLink" idbd="<?=$row->idwallPosts?>">
		View Comments (<?=$query->num_rows()?>)</a>&nbsp;<span class="font1"> |&nbsp;</span> <span class="font1"><?=date('m/d/Y h:ia ', strtotime($row->entryCreationDateTime))?></span></td>
		<td style="height: 19px"></td>
	</tr>
	<tr>
		<td valign="top">
        	<span class="commentsList" id="viewComments-<?php echo $row->idwallPosts; ?>" style="width: 104%; display: none">
<?php	$query1 = $this->db->query("SELECT * FROM wallpostcomments wp INNER JOIN users u ON u.userid = wp.userid WHERE wallPostId = '{$row->idwallPosts}' ORDER BY wp.idwallPostComments ASC");
		foreach($query1->result() as $row1)
			if ($query->num_rows() > 0) { ?>
			<div id="commentsList" style="width: 96%">
			<table cellpadding="0" cellspacing="0" style="width: 408px; height: 5px;" class="style1 commentStyle">
			<tr>
			<td valign="top" style="width: 10px">
			<img style="padding: 3px" id="defaultImg a0" src="<?=base_url().$row1->defaultImgURI?>" align="left" width="25px" height="25px" />
			&nbsp;</td>
			<td valign="top" style="width: 319px">
			<a href="<?=base_url()?>index.php/routers/regUserDash?id=<?=$row->userid?>&requestedPageType=userProfiles" class="font1 link-font1"><b><?=$row1->firstname.' '.$row1->lastname?> </b></a><?=$row1->entryData."<br><!--<img delComment='$row1->idwallPostComments' src='".base_url().$ldr."images/dashboard/delButton.png' alt='Suni' style='float:right;' />-->".date('m/d/Y h:ia ', strtotime($row1->DateTimeCreated))?></a>
			</td>
		</tr>
	</table>
	</span>
	<?php } ?>
		</td>
		<td></td>
	</tr>
	<tr>
		<td valign="top" style="width: 408px" rowspan="2">
		<span style="display: none" id="commentBox-<?=$row->idwallPosts?>">
			<input placeholder="Write a comment..." class="textbox1" postuserid="<?=$row->postingUserId?>" id="commentBox-<?=$row->idwallPosts?>" style="width: 398px"></input>
		</span>
		</td>
		<td style="height: 1px"></td>
	</tr>
	<tr>
		<td style="width: 65px"></td>
		<td style="height: 18px; width: 33px"></td>
	</tr>
</table>

		</td>
	</tr>
</table>

</body>

</html>
<?php } ?>